package com.yq.day71;

import java.io.File;
import java.lang.reflect.Field;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/01 19:3
 * /* 设计一个方法如下，要求该方法能修改任意对象中，指定成员变量的
 * * @param newValue 要修改成员变量值的新值 */

public class Demo01 {

    public static void setAll(Object targetObj,String fieldName,Object newValue) throws NoSuchFieldException, IllegalAccessException {
        Class<?> aClass = targetObj.getClass();
        Field declaredField = aClass.getDeclaredField(fieldName);
        declaredField.setAccessible(true);
        declaredField.set(targetObj,newValue);
        System.out.println(targetObj);

    }
}
